#include <stdio.h>
#include <stdlib.h>
int main()
{
    int i, j, flag = 1, kind, n;
    
    scanf("%d", &n);
    int **arr = (int **)calloc(n, sizeof(int *));
    scanf("%d", &kind);
    for (i = 0; i < n; i++)
    {
        arr[i] = (int*)calloc(n, sizeof(int));
        for (j = 0; j < n; j++)
        {
            scanf("%d", &arr[i][j]);
        }
    }
    if (0 == kind)
    {
        int* num = (int *)calloc(n, sizeof(int));
        for (i = 0; i < n; i++)
        {
            for (j = 0; j < n; j++)
                if (1 == arr[i][j])
                {
                    num[i]++;
                }
        }
        for (i = 0; i < n; i++)
        {
            if (num[i] == 0 || num[i] % 2)
            {
                flag = 0;
                break;
            }
        }
        free(num);
        num = NULL;
    }
    else if (1 == kind)
    {
        int* begin = (int *)calloc(n, sizeof(int));
        int* end = (int *)calloc(n, sizeof(int));
        int* num = (int *)calloc(n, sizeof(int));
        for (i = 0; i < n; i++)
        {
            for (j = 0; j < n; j++)
                if (1 == arr[i][j])
                {
                    begin[i]++;
                    end[j]++;
                    num[i]++;
                }
        }
        for (i = 0; i < j; i++)
            if (num[i] == 0 || begin[i] != end[i])
                flag = 0;
        free(num),free(end),free(begin);
        num = end = begin = NULL;
    }
    else ;
    if (flag)
        printf("Y");
    else
        printf("N");
    for (i = 0; i < n; i++)
    {
        free(arr[i]);
        arr[i] = NULL;
    }
    free(arr);
    arr = NULL;

    return 0;
}
